package hello.tencentcloud;

import java.lang.reflect.Type;
import com.google.gson.JsonSyntaxException;
import com.google.gson.reflect.TypeToken;
import com.tencentcloudapi.common.exception.TencentCloudSDKException;
import com.tencentcloudapi.common.AbstractClient;
import com.tencentcloudapi.common.profile.ClientProfile;
import com.tencentcloudapi.common.JsonResponseModel;
import com.tencentcloudapi.common.Credential;
import com.tencentcloudapi.aai.v20180522.models.*;

public class TextTranslateClient extends AbstractClient{
    private static String endpoint = "tmt.tencentcloudapi.com";
    private static String version = "2018-03-21";

    /**
     * 构造client
     * @param credential 认证信息实例
     * @param region	产品地域
     */
    public TextTranslateClient(Credential credential, String region) {
        this(credential, region, new ClientProfile());
    }

    /**
     * 构造client
     * @param credential 认证信息实例
     * @param region	产品地域
     * @param profile 配置实例
     */
    public TextTranslateClient(Credential credential, String region, ClientProfile profile) {
        super(TextTranslateClient.endpoint, TextTranslateClient.version, credential, region, profile);
    }

    /**
     *识别60s内的短语音。
     * @param TextTranslateRequest
     * @return TextTranslateResponse
     * @throws TencentCloudSDKException
     */
    public TextTranslateResponse Translate(TextTranslateRequest req) throws TencentCloudSDKException{
        JsonResponseModel<TextTranslateResponse> rsp = null;
        try {
            Type type = new TypeToken<JsonResponseModel<TextTranslateResponse>>() {}.getType();
            rsp  = gson.fromJson(this.internalRequest(req, "TextTranslate"), type);
        } catch (JsonSyntaxException e) {
            throw new TencentCloudSDKException(e.getMessage());
        }
        return rsp.response;
    }

}